let addImg = document.getElementsByClassName("add-img");
let delImg = document.getElementsByClassName("del-img");
let biImg = document.getElementsByClassName("bi-img");
let text = document.getElementById("text");
let textM = document.getElementById("message-text");
let userD = document.getElementById("userD");
let text1 = document.getElementById("txtD");
let text2 = document.getElementById("messageText");
let gao = document.getElementsByClassName("gao");
let li = document.getElementsByTagName("li")
console.log(li.length)
let numD = li.length;
let numberD = 0;
let user;

//在数据库内查找用户名
let currentUserId = localStorage.getItem("employeeId");
for(a of AllStaffList){
    if (a.Id == currentUserId){
        user = a;
        break;
    }
}
for(b of AllStudentList){
    if(b == currentUserId){
        addImg[0].remove();
        biImg[0].remove();
        delImg[0].remove();
    }
}

//点击添加按钮
function newAdd() {
    text.value = "";
    textM.value = "";
    userD.innerText = user.Name;
}

// 点击添加公告里面的发布按钮
function announceAdd() {
    let height = document.getElementById("height");
    let newAdd = height.cloneNode(true);
    let announcetxt = newAdd.getElementsByClassName("announcetxt");
    let zhengwenD = newAdd.getElementsByClassName("zhengwenD");
    let fabuD = newAdd.getElementsByClassName("fabuD");
    let announceIconImg = newAdd.getElementsByClassName("announceIconImg");
    numD++;
    announceIconImg[0].innerText = numD;
    zhengwenD[0].innerText = textM.value;
    announcetxt[0].innerText = text.value;
    fabuD[0].innerText = userD.innerText;
    tableAdd.appendChild(newAdd);
}

//点击修改按钮
function reviseD(object) {
    let xiugaContent = document.getElementsByClassName("xiugai-content");
    let tipD = document.getElementsByClassName("tipD");
    let xiuD = document.getElementsByClassName("xiuD");
    let liD = object.parentNode;
    let announcetxt = liD.getElementsByClassName("announcetxt");
    let zhengwenD = liD.getElementsByClassName("zhengwenD");
    let announceIconImg = liD.getElementsByClassName("announceIconImg");
    let fabuD = liD.getElementsByClassName("fabuD");
    numberD = announceIconImg[0].innerText;
    text1.value = announcetxt[0].innerText;
    text2.value = zhengwenD[0].innerText;
    if(fabuD[0].innerText != user.Name){
        xiugaContent[0].style.display = "none";
        xiuD[0].style.display = "none";
        tipD[0].style.display = "block";
        return;
    }else{
        xiuD[0].style.display = "block";
        xiugaContent[0].style.display = "block";
        tipD[0].style.display = "none";
    }
}

//点击修改公告界面的修改按钮
function announceRevise() {
    let announcetxt = gao[numberD-1].getElementsByClassName("announcetxt");
    let zhengwenD = gao[numberD-1].getElementsByClassName("zhengwenD");
    announcetxt[0].innerText = text1.value;
    zhengwenD[0].innerText = text2.value;
}

// 点击删除按钮
function announceDel(obj) {
    let liD = obj.parentNode;
    let announceIconImg = liD.getElementsByClassName("announceIconImg");
    let fabuD = liD.getElementsByClassName("fabuD");
    for(let i = 0; i < gao.length;i++){
        if(announceIconImg[0].innerText != 1 && (i+1) > announceIconImg[0].innerText){
            let iconImg = gao[i].getElementsByClassName("announceIconImg");
            iconImg[0].innerText = i;
        }
    }
    if(announceIconImg[0].innerText != 1 && fabuD[0].innerText == user.Name){
        $(obj).parent().remove();
        numD--;
    }
}

//点击查看按钮
function inspectD(content) {
    let serialD = document.getElementById("serialD");
    let titleD = document.getElementById("titleD");
    let textcontentD = document.getElementById("textcontentD");
    let faburenD = document.getElementById("faburenD");

    let liD = content.parentNode;
    let announcetxt = liD.getElementsByClassName("announcetxt");
    let zhengwenD = liD.getElementsByClassName("zhengwenD");
    let fabuD = liD.getElementsByClassName("fabuD");
    let announceIconImg = liD.getElementsByClassName("announceIconImg");

    serialD.innerText = announceIconImg[0].innerText;
    titleD.innerText = announcetxt[0].innerText;
    textcontentD.innerText = zhengwenD[0].innerText;
    faburenD.innerText = fabuD[0].innerText;

    if(textcontentD.innerText == "") {
        textcontentD.innerText = "无";
    }
}

//鼠标移入点亮

function mouOverD(obj) {
    obj.style.backgroundImage = "linear-gradient(to right, rgba(230, 100, 101, 0.7), rgba(145, 152, 229, 0.7))";
}

function mouOutD(obj) {
    obj.style.backgroundImage = "";
}